package com.heima.user.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.LoginDto;
import com.heima.model.user.dtos.RegisteredDto;
import com.heima.model.user.dtos.UserDto;
import com.heima.user.service.ApUserService;
import com.netflix.client.http.HttpRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/api/v1/login")
@Api(value = "app端用户登录-控制器")
public class ApUserLoginController {
    @Autowired
    private ApUserService service;

    /**
     * 用户登录
     *
     * @param dto
     * @return
     */
    @PostMapping("/login_auth")
    @ApiOperation("用户登录")
    public ResponseResult login(@RequestBody LoginDto dto) {
        return service.login(dto);
    }

    /**
     * 用户注册校验验证码
     *
     * @return
     */
    @PostMapping("/registered")
    public ResponseResult registered(@RequestBody RegisteredDto dto, HttpSession session) {
        return service.registered(dto,session);
    }

    /**
     * 短信发送
     *
     * @param phone
     * @return
     */
    @GetMapping("/sendMsg/{phone}")
    public ResponseResult sendMsg(@PathVariable String phone, HttpSession session) {
        return service.sendMsg(phone, session);
    }

    /**
     * 注册新用户
     * @param dto
     * @return
     */
    @PostMapping("/add/{phone}")
    public ResponseResult addApUser(@RequestBody UserDto dto,@PathVariable String phone){
        return service.addApUser(dto,phone);
    }

}
